home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / bcpp / cmmdlg / port_.pas < prev    next >
Pascal/Delphi Source File  |  1992-09-07  |  7KB  |  408 lines

  1. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  2. {   \\\                                    }
  3. {  -(j)-                                   }
  4. {    /juanca «                             }
  5. {    ~                                     }
  6. {$D ⌐ ACASA 1989-1992, All rights reserved }
  7. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  8.  
  9. { an OO shell for DeviceContext, place in your tPort Object any method
  10. that makes your life with GDI easier
  11. }
  12.  
  13. UNIT PORT_;
  14. {$C MOVEABLE DEMANDLOAD DISCARDABLE}
  15. INTERFACE
  16.    USES
  17.      WOBJECTS,
  18.      WINTYPES;
  19.  
  20.    CONST
  21.      NULL = 0;
  22.  
  23.    TYPE
  24.      TPolyPoints = array[0..MaxInt div 4] of TPoint;
  25.      PPolyPoints = ^TPolyPoints;
  26.  
  27.      PPort = ^TPort;
  28.      Super      = TObject;
  29.      TPort = OBJECT (Super)
  30.        CONSTRUCTOR
  31.          init;
  32.        CONSTRUCTOR
  33.          initD(hdev:THandle);
  34.        CONSTRUCTOR
  35.          initGet(iwin:PWindowsObject); { get the DeviceContext from a tWindow }
  36.        CONSTRUCTOR
  37.          compatible(dc:PPort);
  38.  
  39.        DESTRUCTOR
  40.          done;
  41.            virtual;
  42.        DESTRUCTOR
  43.          delete;
  44.            virtual;
  45.  
  46.  
  47.        FUNCTION
  48.          context:THandle;
  49.            virtual;
  50.        PROCEDURE
  51.          set_context( newHDC:THandle);
  52.  
  53.        FUNCTION
  54.        isPrinter :Boolean;  { always FALSE, tPrinter returns TRUE }
  55.  
  56.        FUNCTION
  57.        cycle :Boolean;
  58.          virtual;
  59.                               { function to call from long painting routines,
  60.                               it exists so when painting to a tPrinter,
  61.                               user can interruput with the PrintAbort dlg
  62.                               }
  63.  
  64.        FUNCTION
  65.          select(obj :THandle):THandle;
  66.  
  67.        FUNCTION
  68.          textOut(x, y:Integer; txt:pChar):Boolean;
  69.  
  70.        PROCEDURE
  71.          setPixel(x, y :Integer; color :TColorRef);
  72.  
  73.        PROCEDURE
  74.          moveTo(x, y:Integer);
  75.        PROCEDURE
  76.          lineTo(x, y:Integer);
  77.  
  78.        FUNCTION
  79.          rectangle(x1, y1, x2, y2:Integer):Boolean;
  80.  
  81.        FUNCTION
  82.          ellipse(x1, y1, x2, y2:Integer):Boolean;
  83.  
  84.        FUNCTION
  85.          polyLine(var points :TPolyPoints; count :Word):Boolean;
  86.  
  87.        FUNCTION
  88.          polygon(var points :TPolyPoints; count :Word):Boolean;
  89.  
  90.        PROCEDURE
  91.          lp2dp(var points; count:Word);
  92.        PROCEDURE
  93.          dp2lp(var points; count:Word);
  94.  
  95.        FUNCTION
  96.          compatibleBitmap(w, h :Integer):HBitmap;
  97.  
  98.        PROCEDURE
  99.          save;
  100.        PROCEDURE
  101.          restore;
  102.  
  103.        FUNCTION
  104.          setROP2(mode:Integer):Integer;
  105.  
  106.  
  107.        FUNCTION
  108.        mapMode :Integer;
  109.  
  110.        PROCEDURE
  111.        setMapMode(mm :Integer);
  112.  
  113.        PROCEDURE
  114.        textExtents(s :pChar; var width, height :Word);
  115.  
  116.  
  117.      PRIVATE
  118.        _hdc : THandle;
  119.        _win : PWindowsObject;
  120.      END;{OBJECT Super}
  121.  
  122.  
  123.  
  124.  
  125. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  126. IMPLEMENTATION
  127.   USES
  128.     WINPROCS,
  129.     STRINGS;
  130.  
  131.   CONST
  132.     mm_DivFactor = 1;
  133.  
  134.   PROCEDURE
  135.   {}
  136.   softYield;
  137.     var
  138.      msg :tMsg;
  139.     begin
  140.       peekMessage(msg, 0, 0, Word(-1), pm_NoRemove)
  141.     end;
  142.  
  143.   CONSTRUCTOR
  144.   TPort.
  145.     {}
  146.   init;
  147.     begin
  148.       Super.init;
  149.       _win := nil;
  150.       _hdc := null
  151.     end;
  152.  
  153.   CONSTRUCTOR
  154.   TPort.
  155.     {}
  156.   initD(hdev:THandle);
  157.     begin
  158.       Super.init;
  159.       _win := nil;
  160.       _hdc := hdev
  161.     end;
  162.  
  163.   CONSTRUCTOR
  164.   TPort.
  165.     {}
  166.   initGet(iwin :PWindowsObject);
  167.     begin
  168.       Super.init;
  169.       _win := iwin;
  170.       if _win <> nil then
  171.         _hdc := getDC(_win^.hwindow)
  172.       else
  173.         _hdc := null
  174.     end;
  175.  
  176.   CONSTRUCTOR
  177.   TPort.
  178.     {}
  179.   compatible(dc:PPort);
  180.     begin
  181.       TPort.initD(createCompatibleDC(dc^.context));
  182.     end;
  183.  
  184.  
  185.   DESTRUCTOR
  186.   TPort.
  187.     {}
  188.   done;
  189.     begin
  190.       if _win <> nil
  191.       then
  192.         releaseDC(_win^.hwindow, context);
  193.       _win := nil;
  194.       _hdc := null
  195.     end;
  196.  
  197.   DESTRUCTOR
  198.   TPort.
  199.     {}
  200.   delete;
  201.     begin
  202.        if _hdc <> null
  203.        then
  204.          deleteDC(_hdc);
  205.       _win := nil;
  206.       _hdc := null
  207.     end;
  208.  
  209.   FUNCTION
  210.   TPort.
  211.     {}
  212.   context:THandle;
  213.     begin
  214.       context := _hdc
  215.     end;
  216.  
  217.   PROCEDURE
  218.   TPort.
  219.     {}
  220.   set_context(newHDC :THandle);
  221.     begin
  222.       _hdc := newHDC;
  223.       _win := nil
  224.     end;
  225.  
  226.   FUNCTION
  227.   tPort.
  228.   {}
  229.   isPrinter :Boolean;
  230.     begin
  231.       isPrinter := FALSE
  232.     end;
  233.  
  234.   FUNCTION
  235.   TPort.
  236.     {}
  237.   cycle:Boolean;
  238.     begin
  239.       cycle := TRUE;
  240.       softYield
  241.     end;
  242.  
  243.   {}
  244.   {}
  245.   FUNCTION
  246.   TPort.
  247.     {}
  248.   select(obj :THandle):THandle;
  249.     begin
  250.       select := selectObject(context, obj)
  251.     end;
  252.  
  253.   {}
  254.   {}
  255.   PROCEDURE
  256.   TPort.
  257.     {}
  258.   setPixel(x, y :Integer; color :TColorRef);
  259.     begin
  260.       WinProcs.setPixel(context, x, y, color)
  261.     end;
  262.  
  263.   {}
  264.   {}
  265.   PROCEDURE
  266.   TPort.
  267.     {}
  268.   moveTo(x, y:Integer);
  269.     begin
  270.       WinProcs.moveTo(context, x, y)
  271.     end;
  272.  
  273.   {}
  274.   {}
  275.   PROCEDURE
  276.   TPort.
  277.     {}
  278.   lineTo(x, y:Integer);
  279.     begin
  280.       WinProcs.lineTo(context, x, y)
  281.     end;
  282.  
  283.   FUNCTION
  284.   TPort.
  285.     {}
  286.   rectangle(x1, y1, x2, y2:Integer):Boolean;
  287.     begin
  288.       rectangle := Word(WinProcs.rectangle(context, x1, y1, x2, y2)) <> 0
  289.     end;
  290.  
  291.   {}
  292.   {}
  293.   FUNCTION
  294.   TPort.
  295.     {}
  296.   ellipse(x1, y1, x2, y2:Integer):Boolean;
  297.     begin
  298.       ellipse := Word(WinProcs.ellipse(context, x1, y1, x2, y2)) <> 0
  299.     end;
  300.  
  301.   FUNCTION
  302.   TPort.
  303.     {}
  304.   polygon(var points :TPolyPoints; count :Word):Boolean;
  305.     begin
  306.       polygon := 0 <> Word(WINPROCS.polygon(context, points, count))
  307.     end;
  308.  
  309.  
  310.   FUNCTION
  311.   TPort.
  312.     {}
  313.   polyLine(var points :TPolyPoints; count :Word):Boolean;
  314.     begin
  315.       polyLine := 0 <> Word(WINPROCS.polyLine(context, points, count))
  316.     end;
  317.  
  318.  
  319.   {}
  320.   {}
  321.   FUNCTION
  322.   TPort.
  323.     {}
  324.   textOut(x, y:Integer; txt:pChar):Boolean;
  325.     begin
  326.       textOut := 0 <> Word(WinProcs.textOut(context, x, y, txt, strLen(txt)));
  327.     end;
  328.  
  329.   PROCEDURE
  330.   TPort.
  331.     {}
  332.   lp2dp(var points; count:Word);
  333.     begin
  334.       LPToDP(context, points, count)
  335.     end;
  336.  
  337.   PROCEDURE
  338.   TPort.
  339.     {}
  340.   dp2lp(var points; count:Word);
  341.     begin
  342.       DPToLP(context, points, count)
  343.     end;
  344.  
  345.   FUNCTION
  346.   TPort.
  347.     {}
  348.   compatibleBitmap(w, h :Integer):HBitmap;
  349.     begin
  350.       compatibleBitmap := createCompatibleBitmap(context, w, h)
  351.     end;
  352.  
  353.   PROCEDURE
  354.   TPort.
  355.     {}
  356.   save;
  357.     begin
  358.       saveDC(context);
  359.     end;
  360.  
  361.   PROCEDURE
  362.   TPort.
  363.    {}
  364.   restore;
  365.     begin
  366.       restoreDC(context, -1)
  367.     end;
  368.  
  369.  
  370.   FUNCTION
  371.   TPort.
  372.     {}
  373.    setROP2(mode:Integer):Integer;
  374.      begin
  375.        setROP2 := WinProcs.setROP2(context, mode)
  376.      end;
  377.  
  378.  
  379.   FUNCTION
  380.   TPort.
  381.    {}
  382.   mapMode :Integer;
  383.     begin
  384.       mapMode := getMapMode(context)
  385.     end;
  386.  
  387.   PROCEDURE
  388.   TPort.
  389.    {}
  390.   setMapMode(mm :Integer);
  391.     begin
  392.       WinProcs.setMapMode(context, mm)
  393.     end;
  394.  
  395.   PROCEDURE
  396.   TPort.
  397.    {}
  398.   textExtents(s :pChar; var width, height :Word);
  399.     var
  400.       size :Longint;
  401.     begin
  402.       size := getTextExtent(context, s, strLen(s));
  403.       height := hiWord(size);
  404.       width  := loWord(size)
  405.     end;
  406.  
  407.  
  408. END.